from multiprocessing import Process,SimpleQueue
import time
import random

def task(resultQueue:SimpleQueue,a:float,b:float) -> float :
    ret = (a**2+b**2)**0.5
    sleepTime = random.uniform(5,10) #假装很忙 要算很多东西
    print("sleep time =",sleepTime)
    time.sleep(sleepTime)
    resultQueue.put(ret)


if __name__=="__main__":
    plist = list()
    qr = SimpleQueue()
    data = 0 #存放结果
    for i in range(0,1000):
        plist.append( Process(target=task,kwargs={"resultQueue":qr , "a":i ,"b":i+2},daemon=True ) )
        plist[i].start()
    for process in plist:
        #等待所有进程运算完成
        if process.is_alive():
            process.join()
        temp_ret = qr.get() #将结果取出
        print("temp_ret=",temp_ret)
        data = data+temp_ret
    print(data)
    

    
    
